<?php
/**
 * Created by PhpStorm.
 * User: coffee
 * Date: 2018/1/22
 * Time: 上午11:12
 */

namespace App\Console\Commands;


use App\Events\StudentCalenderPresentReminder;
use App\Facades\AliyunKafka;
use App\Models\EventStudentCalendarPresent;
use Illuminate\Console\Command;

class SendCalendarPresentReminderCommand extends Command
{
    protected $signature = 'reminder:student_calendar_present';

    protected $description = 'send message which about 2018 calendar present';

    public function fire()
    {
        $this->line('start send event to kafka (EventStudentCalendarPresent)');
        do{
            $records = EventStudentCalendarPresent::where('status', EventStudentCalendarPresent::STATUS_Created)
                ->where('express_id',  '>', 0)->take(20)->get();

            foreach ($records as $record) {
                $event = new StudentCalenderPresentReminder();
                $event->studentId = $record->getStudentId();
                $event->expressId = $record->getExpressId();
                AliyunKafka::push($event);
                $record->setStatus(EventStudentCalendarPresent::STATUS_Post);
                $record->save();
            }
        } while($records->count() == 20 );
    }



}